<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ include file="/WEB-INF/taglib.jsp"%>
<jsp:include page="/WEB-INF/common/head.jsp" flush="true" />
<script type="text/javascript">
if (self != top) {  //主页不允许在iframe中
	top.window.location.reload();
}

//修改密码
function updatePassword() {
	top.window.subPage.loadCurrDatagrid = function() {
		showMsg("密码修改成功！");
	}
	top.openWindow("修改密码", "${context_path}/pwdSetting", {size: '500x350'});
}

</script>
<script type="text/javascript" src="${res_url}js/menu.js"></script>
<style type="text/css">
.head{background: #09C; font-size: 14px; color: white; height: 50px; line-height: 50px; padding: 0px 8px; overflow: hidden;}
.head table{border-spacing: 0px; width: 100%;}
.head table,tr,td,th{padding: 0px;}
.head .rtool a{color: white;}
.head .rtool a.l-btn-plain:hover{color: black;}
.head .rtool a.l-btn-plain.m-btn-plain-active{color: black;}

.easyui-tabs .tabs{border-color: #A5C4EF;}
.easyui-tabs .tabs li a.tabs-inner{border-radius: 2px 2px 0 0;}

.tree-node {padding: 8px 0px;}
.tree-node-hover{background: #465467; color: white;}
.tree-node-selected{background: #0099cc; color: white;}
.tree-node .tree-title{font-size: 13px; font-weight: normal; color: #fff; }

.left{background-color: #424f63;}
.menu_head{height: 30px;line-height: 30px;background: #4e5f77;color: #aeb9c2;text-align: center;}
.layout-expand-north, .layout-expand-west{height: 0px;}

.tree-expanded{
    background: url('${res_url}css/images/tree_icons_main.png') no-repeat -18px 0px;
}
.tree-collapsed {
    background: url('${res_url}res/css/images/tree_icons_main.png') no-repeat 0px 0px;
}
.tree-icon {
    color: #BFBFBF;
    font-size: 12px;
    line-height: 18px;
}


</style>
  	<input id="roleId" type="hidden" value="${roleId}"/>

<div id="layout" class="easyui-layout" data-options="fit:true, border:false">

	<div data-options="region:'north',border:false, collapsedSize:0" style="height:50px;">
		<div class="head"><table><tr>
		
			<td width="10%" style="font-size: 14px;">BI管理门户系统</td>
			<td width="40%" style="font-size: 25px;">	
			  <div id="menu_head" style="font-size: 25px;">		
     	 <a href="#" class="easyui-linkbutton" data-options="plain:true" style="font-size: 25px;margin-right: 10px;" id = "person" onclick="person()" >个人文件夹</a>  
		 <a href="#" class="easyui-linkbutton" data-options="plain:true" style="font-size: 25px;margin-right: 10px" id = "public" onclick="publicMenu()">公共目录</a>  
		 <a href="#" class="easyui-linkbutton" data-options="plain:true" style="font-size: 25px;margin-right: 10px" id = "sysConfig" onclick="loadTree()" >系统设置</a>  
			</div>
			</td>
			<td width="50%" align="right" style="font-size: 12px;">
				<div class="easyui-panel rtool" data-options="border:false" style="text-align: right; background: #09C; color: white; margin-top: -1px;">
			        <a href="#" class="easyui-menubutton" data-options="menu:'#mm1'">	${sessionScope.sysUser.name}</a>
			    </div>
			    <div id="mm1" style="width:150px;">
			        <div data-options="iconCls:'icon-edit'" onclick='updatePassword()'>修改密码</div>
			        <div class="menu-sep"></div>
			        <div data-options="iconCls:'icon-undo'" onclick="location.href='${context_path}/loginOut'">退出</div>
			    </div>
			</td>
		</tr>
		<tr>
		</tr>	
		</table>
		</div >
		</div>	
	<div id="west" class="scrollbar" data-options="region:'west',split:true, border:false, collapsedSize:0" style="width:200px;background-color: #424f63;color:white">
		<div class="zsy_menu">
			<div class="menu_head">菜单导航</div>
	        <ul id="menuTree"></ul>
	    </div>
	</div>
	<div data-options="region:'center', border:false">
	    <div id="mainTabs" style="height:250px">
	        <div title="首页">
	            <iframe src="${context_path}/sys/obj" class="easyui-panel" data-options="fit:true,border:false" frameborder="0"></iframe>
	        </div>
	    </div>
	</div>

</div>

<div id="tabsMenu">
    <div data-options="iconCls:'glyphicon-refresh'" type="refresh" style="font-size: 12px;">刷新</div>
    <div class="menu-sep"></div>
    <div data-options="iconCls:'glyphicon-remove'" type="close" style="font-size: 12px;">关闭</div>
    <div data-options="iconCls:''" type="closeOther">关闭其他</div>
    <div data-options="iconCls:''" type="closeAll">关闭所有</div>
</div>

<div id="mm" class="easyui-menu" style="width:80px;">
<div onclick="append()">新增目录</div>
<div onclick="del()">删除目录</div>
<div onclick="update()">更新目录</div>
 </div> 
<div id="tabTools" style="border: 0px; border-bottom: 1px solid #D3D3D3;">
	<a id="fullScreen" href="###" class="easyui-linkbutton" plain="true" iconCls="glyphicon-fullscreen" onclick="fullScreen(this)"></a>
</div>
   
<script>
var role;
var siteDatagrid = $("#menuTree");
$(function() {
	//屏蔽浏览器右键菜单  
	document.oncontextmenu = function(){  
	    return false;   
	} 
	role = $("#roleId").val();
	if(role!="1"&&role!="2"){
		$("#sysConfig").hide();
	}
});

/**
 * 加载菜单
 */
function loadTree() {
	$.post("${context_path}/getMenu", function(data) {
		var menulist = [];
		$.each(data, function(i, item) {
			menulist.push({
				id: item.id,
				text: item.menu_name,
				attributes:"/Portal"+item.menu_url, 
				parent_id: item.parent_id,
				
				iconCls: item.icon
			});
		});
		
		for(var i = 0; i < menulist.length; i++) {
			var children = menulist[i].children || [];
			for(var j = 0; j < menulist.length; j++) {
				if(menulist[j].parent_id == menulist[i].id) {
					children.push(menulist[j]);
				}
			}
			menulist[i].children = children;
		}
		
		var treeData = [];
		$.each(menulist, function(i, item) {
			if(item.parent_id == 0) {
				treeData.push(item);
			}
		});
		$("#menuTree").tree({
			data: treeData,
			onBeforeSelect: treeBeforeSelect, 
			onSelect: treeSelect,
			onContextMenu: function(e,row){ //这个就是树形菜单加载鼠标右键菜单的代码
				e.preventDefault();
				}
			
		});
	});
}

function person(){
		$.post("${context_path}/sys/site/getPersonMenu", function(data) {
			var menulist = [];
			$.each(data.data, function(i, item) {
				menulist.push({
					id: item.id,
					text: item.name,
					parent_id: item.parent_id,
					attributes:"${context_path}"+item.url, 
				});
			});
			
			for(var i = 0; i < menulist.length; i++) {
				var children = menulist[i].children || [];
				for(var j = 0; j < menulist.length; j++) {
					if(menulist[j].parent_id == menulist[i].id) {
						children.push(menulist[j]);
					}
				}
				menulist[i].children = children;
			}
			
			var treeData = [];
			$.each(menulist, function(i, item) {
				if(item.parent_id == 0) {
					treeData.push(item);
				}
			});
			$("#menuTree").tree({
				data: treeData,
				onBeforeSelect: treeBeforeSelect, 
				onSelect: treeSelect,
				onContextMenu: function(e,row){ //这个就是树形菜单加载鼠标右键菜单的代码
					e.preventDefault();
					}
			});
		});	
}

function publicMenu(){

	$.post("${context_path}/sys/site/getAllList", function(data) {
		var menulist = [];
		$.each(data, function(i, item) {
			menulist.push({
				id: item.id,
				text: item.name,
				parent_id: item.parent_id,
				dirType:item.dirType,
				attributes:"${context_path}"+item.url
			});
		});
		
		for(var i = 0; i < menulist.length; i++) {
			var children = menulist[i].children || [];
			for(var j = 0; j < menulist.length; j++) {
				if(menulist[j].parent_id == menulist[i].id) {
					children.push(menulist[j]);
				}
			}
			menulist[i].children = children;
		}
		
		var treeData = [];
		$.each(menulist, function(i, item) {
			if(item.parent_id == 0) {
				treeData.push(item);
			}
		});
		$("#menuTree").tree({
			data: treeData,
			onBeforeSelect: treeBeforeSelect, 
			onSelect: treeSelect,
			onContextMenu: function(e,row){ //这个就是树形菜单加载鼠标右键菜单的代码
				e.preventDefault();
				//选中状态 
				$('#mm').menu('show', {
				left: e.pageX,
				top: e.pageY
				});
				}
		});
	});	
}


$(function() {
	//加载菜单
	person();
});



/**
 * 菜单事件
 */
function treeBeforeSelect(node) {
    if(node.children && node.children.length > 0) {
        if(node.state == "open") {
            $(this).tree("collapse", node.target);
        }else {
            $(this).tree("expand", node.target);
        }
        return false;
    } 
}
/**
 * 菜单事件
 */
function treeSelect(node) {
	addMainTab(node.text, node.attributes);
}

/**
 * 增加一个主窗口
 */
function addMainTab(text, url) {
	if(!mainTabs.tabs("exists", text)) {
		mainTabs.tabs('add',{
            title: text,
            content:'<iframe src="' + url + '" class="easyui-panel" data-options="fit:true,border:false" frameborder="0"></iframe>',
            closable:true
        });
    }else {
    	mainTabs.tabs("select", text);
    	//刷新
    	mainTabs.tabs('getSelected').panel('panel').find('iframe').attr("src", url)
    }
}

/**
 * 全屏
 */
function fullScreen() {
	if($("#fullScreen").find(".glyphicon-screenshot").length > 0) {
		$("#layout").layout('expand', 'west').layout('expand', 'north');
		$("#fullScreen").find(".l-btn-icon").addClass("glyphicon-fullscreen").removeClass("glyphicon-screenshot");
	}else {
		$("#layout").layout('collapse', 'north').layout('collapse', 'west');
		$("#fullScreen").find(".l-btn-icon").addClass("glyphicon-screenshot").removeClass("glyphicon-fullscreen");
		$(".layout-expand").hide();
	}
	
}
function append(){

	var rowsSel = siteDatagrid.tree('getSelected');
	
	/* if(rowsSel.length != 1) {
		showWarnMsg("请选择需要编辑的一条数据！");
		return;
	}
	if(rowsSel[0].dirType !=1) {
		showWarnMsg("请选择公共目录进行目录管理");
		return;
	}else{ */
	if(rowsSel!=null&&rowsSel.dirType!=1){
			showWarnMsg("请选择公共目录进行目录管理");
			return;
	}else{
	var id = rowsSel.id;
	top.window.subPage.loadCurrDatagrid = function() {
		showMsg("增加成功！");
		publicMenu();
	}
	top.openWindow("站点管理-增加站点", '${context_path}/sys/site/add?pid='+id, {size: '600x400'});
	}
}
function del(){
	//删除对象
	var rowsSel = siteDatagrid.tree('getSelected');
	
	/* if(rowsSel.length != 1) {
		showWarnMsg("请选择需要编辑的一条数据！");
		return;
	} */
	if(rowsSel!=null&&rowsSel.dirType !=1) {
		showWarnMsg("请选择公共目录进行目录管理");
		return;
	}else{
	var id = rowsSel.id;
	
	confirmMsg("确认删除？", function() {
		$.post("${context_path}/sys/site/delete", {"ids": id}, function(data) {
			if(data.code == 0){
				showMsg("删除成功")
				publicMenu();
			}else{
				showMsg(data.msg);	
			}
			
			siteDatagrid.treegrid("reload");
		});
	});
	}
}
function update(){
	var rowsSel = siteDatagrid.tree('getSelected');
	
/* 	if(rowsSel.length != 1) {
		showWarnMsg("请选择需要编辑的一条数据！");
		return;
	} */
	if(rowsSel!=null&&rowsSel.dirType !=1) {
		showWarnMsg("请选择公共目录进行目录管理");
		return;
	}else{
	var id = rowsSel.id;
	top.window.subPage.loadCurrDatagrid = function() {
		showMsg("更新成功！");
		publicMenu();
	}
	top.openWindow("对象管理-编辑", '${context_path}/sys/site/add?gid=' + id, {size: '600x400'});
	}
}

</script>
  <jsp:include page="/WEB-INF/common/dialogWindow.jsp" flush="true" />
   <jsp:include page="/WEB-INF/common/foot.jsp" flush="true" />
